package com.videoweb.ying.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.baomidou.mybatisplus.plugins.Page;
import com.videoweb.ying.dto.DataKeyDto;
import com.videoweb.ying.service.TDataKeyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.videoweb.base.BaseController;
import com.videoweb.ying.service.TQqService;

@RestController
@RequestMapping("/openapi")
public class ApiQQController extends BaseController{

	@Autowired
	private TQqService tQqService;

	@Autowired
	private TDataKeyService dataKeyService;

	/**
	 * 获取QQ链接
	 * @param modelMap
	 * @param request
	 * @return
	 */
	@PostMapping("/getQqInfo")
	public Object getQqInfo(ModelMap modelMap, HttpServletRequest request)
	{
		 List<Map<String,Object>> tQ = new ArrayList<Map<String,Object>>();
		 tQ = tQqService.selectQQurl();
		 if(tQ != null && !"".equals(tQ)&&tQ.size()>0)
		 {
			 Map<String,Object> tf = new HashMap<String,Object>();
			 tf = tQ.get(0);
			 modelMap.put("qq", tf.get("name"));
		 }
		 modelMap.put("retCode", "1");
		 modelMap.put("retMsg", "查询成功");
		 return  setSuccessResponse(modelMap);
	}

	/**
	 * 获取QQ链接
	 * @param modelMap
	 * @param request
	 * @return
	 */
	@PostMapping("/getQq")
	public Object getQq(ModelMap modelMap, HttpServletRequest request) {
		List<Map<String,Object>> records = dataKeyService.selectListByQQ();
		modelMap.put("retCode", "1");
		modelMap.put("retMsg", "查询成功");
		return  setSuccessResponse(modelMap,records);
	}

	/**
	 * getDataByType
	 * @param modelMap
	 * @param request
	 * @return
	 */
	@PostMapping("/queryDataByType")
	public Object queryDataByType(ModelMap modelMap, HttpServletRequest request , @RequestBody DataKeyDto dto) {
		if (dto != null && !"".equals(dto)) {
				String code = String.valueOf(dto.getCode());
				List<Map<String,Object>> records = dataKeyService.getDataByType(code);
				modelMap.put("retCode", "1");
				modelMap.put("retMsg", "查询成功");
				return  setSuccessResponse(modelMap,records);
		}
		return null;
	}
}
